<template lang="pug">
  div(id="charts" style="height:100%;display:flex;flex-direction: column;")
    div(style="flex:1;")
      keep-alive
        kalix-chart(bizKey="makingstat" title="阅卷统计" v-bind:autoload="true"
        v-bind:chartTargetUrl="targetUrl" width="100%" height="450px"
        bizSearch="MakingStatSearch" v-on:dataDblclick="dataDblclick" v-on:searchAfter="searchAfter")
    div(style="flex:10%;")
      keep-alive
        kalix-table(bizKey="makingstatTable" title='批阅列表' ref="makingstatTable" v-bind:bizDialog="bizDialog"
        v-bind:jsonStr="hisJsonStr" v-bind:toolbarBtnList="toolbarBtnList" v-bind:btnList="btnList"
        v-bind:targetURL="targetOverReadURL" v-bind:tableFields="tableFields"
        )
</template>

<script type="text/ecmascript-6">
  import {MakingStatURL, MakingStatOverReadURL} from '../config.toml'
  import {MakingStatBtnList} from './config'

  export default {
    name: 'kalix-exam-makingstat',
    data() {
      return {
        targetUrl: MakingStatURL,
        option: undefined,
        toolbarBtnList: [
          {id: 'add', isShow: false}
        ],
        tempOverReadURL: MakingStatOverReadURL,
        targetOverReadURL: MakingStatOverReadURL + '/-1',
        hisJsonStr: '',
        tableFields: [
          {prop: 'name', label: '考试名称'},
          {prop: 'stem', label: '考题'},
          {prop: 'perScore', label: '满分'},
          {prop: 'score', label: '批阅分'},
          {prop: 'userName', label: '考生'}
        ],
        btnList: MakingStatBtnList,
        bizDialog: [
          {id: 'view', dialog: 'MakingstatView'}
        ],
        appendCondition: {}
      }
    },
    methods: {
      dataDblclick(params) {
        let subject = params.dataParam.name
        let jsonStr = params.searchParam.jsonStr
        if (jsonStr && jsonStr.length) {
          let searJson = JSON.parse(jsonStr)
          this.$KalixEventBus.$emit('onSearchBtnClick', {
            jsonStr: `{'%subject%':'${subject}','dateBegin':'${searJson.dateBegin}','dateEnd': '${searJson.dateEnd}'}`
          })
        }
        console.group('dataDblclick')
        console.log('subject', subject)
        console.log('jsonStr', jsonStr)
        console.groupEnd()
        // {
        // jsonStr          :
        //   "{"dateBegin": "2018-12-1 0:0:0","dateEnd": "2018-12-29 0:0:0"}"
        // }

        // this.$refs.makingstatTable.updateSearchParam({subject})
        // this.hisJsonStr = `{'subject': '${subject}'}`
        // if (jsonStr && jsonStr.length) {
        //   let searJson = JSON.parse(jsonStr)
        //   let dateBegin = searJson.dateBegin
        //   let dateEnd = searJson.dateEnd
        //   this.hisJsonStr = `{'subject':'${subject}','dateBegin':'${dateBegin}','dateEnd': '${dateEnd}'}`
        //   this.appendCondition = `{'subject':'${subject}'}`
        // }
        // console.log('this.hisJsonStr=====================', this.hisJsonStr)
        // this.targetOverReadURL = MakingStatOverReadURL + '/' + subject
      },
      searchAfter(bizkey) {
        if (bizkey === 'makingstat') {
          this.targetOverReadURL = MakingStatOverReadURL + '/-1'
        }
      }
    }
  }
</script>

<style scoped>

</style>
